package com.ncp.servlet.product;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ncp.model.biz.news.*;
import com.ncp.model.biz.product.ProductManager;
import com.ncp.model.entity.product.ProductBasicBean;
import com.ncp.model.entity.product.ProductBasicIndex;

public class ProductClServlet extends HttpServlet {
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=UTF-8");
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		String type=request.getParameter("type");
		
		if(type.equals("addProduct")){
			String name=request.getParameter("name");
			String picture=request.getParameter("picture");
			String introduction=request.getParameter("introduction");
			boolean b=new ProductManager().addProduct(name,introduction,picture);
			if(b){
				response.sendRedirect("pages/admin/operateOK.jsp");
			}else{
				out.print("出错了！");
			}
		}else if(type.equals("content")){
			String id=request.getParameter("id");
			ProductBasicIndex pb=new ProductManager().getProduct(id);
		
			request.setAttribute("pb", pb);
			request.getRequestDispatcher("pages/product/product.jsp").forward(request, response);
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doGet(request, response);
	}

}
